﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimViec.MP
{
    public partial class fontend : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            if (Session["NguoiDung"] != null)
            {
                pnLogin.Visible = true;
                pnNoLogin.Visible = false;
                DAL.User user = BLL.NguoiDung.NguoiDung.Get_UserEmail(Session["NguoiDung"].ToString());
                lbUser.Text = user.UserName;
            }
            else
            {
                pnLogin.Visible = false;
                pnNoLogin.Visible = true;
            }
        }

        protected void btLogin_Click(object sender, EventArgs e)
        {
            if (BLL.NguoiDung.NguoiDung.Login(txtUserName.Text, txtMK.Text))
            {
                Session["NguoiDung"] = txtUserName.Text;
                Response.Redirect("/nguoi-dung/My-SVCareer.html");
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Sai tên đăng nhập hoặc mật khẩu!');", true);
                return;
            }
        }

        protected void lbtLogOut_Click(object sender, EventArgs e)
        {
            Session.Remove("NguoiDung");
            Response.Redirect("/");
        }

    }
}